//
//  BwtServiceAdManager.m
//  bwt_ad_flutter
//
//  Created by 帅 on 2025/6/24.
//

#import "BwtServiceAdManager.h"
#import "BwtServiceAd.h"
#import "BwtAdLogManager.h"
@implementation BwtServiceAdManager



+ (BwtServiceAdManager *)getBwtBannerAdManager {
    static BwtServiceAdManager *bwtServiceAdManager;
    if(!bwtServiceAdManager) {
        bwtServiceAdManager = [[BwtServiceAdManager alloc] init];
        [bwtServiceAdManager initData];
    }
    return bwtServiceAdManager;
}

- (void)initData{
    if (!_serviceAdMap) {
        _serviceAdMap = [[NSMutableDictionary alloc] initWithCapacity:0];
    }
}
- (void)loadServiceAd:(AdParams*)adParams isRequestIdfa:(bool)isRequestIdfa{
    BwtServiceAd *serviceAd = [[BwtServiceAd alloc] init];
    serviceAd.adParams = adParams;
    serviceAd.isRequestIdfa = isRequestIdfa;
    NSString *adId = adParams.adId;
    [_serviceAdMap setObject:serviceAd forKey:adId];
    [[BwtAdLogManager getBwtAdLogManager] log:@"开始加服务类型广告, adId: %@", adParams.adId];
    [serviceAd loadBannerAd];
    
}


- (UIView *)getBannerAdView:(NSString*)adId{
    if (adId) {
        BwtServiceAd *serviceAd = _serviceAdMap[adId];
        if (serviceAd) {
            return serviceAd.serviceAdView;
        }
    }
    return nil;
}

- (void)releaseAd:(NSString*)adId{
    if (adId) {
        BwtServiceAd *_serviceAd = _serviceAdMap[adId];
        if (_serviceAd) {
            [_serviceAd releaseAd];
            [_serviceAdMap removeObjectForKey:adId];
            
            [[BwtAdLogManager getBwtAdLogManager] log:@"服务类型广告已释放, adId: %@", adId];
        }
    }
}

@end
